Home Java Docker
Home     Java

Java Topic

What is Java
History of Java
Freature of Java
Difference Between Java & C++
Java Environment Set Up
Java Hello World Program & its Internal Process
Java Hello World Program
JDK, JRE and JVM
Java Variables
Java Data Types & Unicode System
Java Operators
Java Keywords
Java Control Statements
Java if else
Java switch
Java for loop
Java While loop
Java Do While loop
Java break
Java continue
Java Oops Concept
Java Object & Class
Java Method
Java Constructor
Java Static Keyword
Java this Keyword
Java Inheritance
Java Hybrid Inheritance
Aggregation(HAS-A)
Java Polymorphism
Java method overloading
Java method overriding
Java Runtime polymorphism
Java Dynamic Binding
Super keyword
Final keyword
Difference Between method overloading and method overriding
Java Abstraction
Java Interface
Abstract class vs Interface
Java Encapsulation
Java Package
Java Access Modifiers
covariant return type
Instance initializer block
Java instanceof operator
Object Cloning in Java
Wrapper classes in Java
Java Strictfp Keyword
Recursion in Java
Java Command Line Arguments
Difference between object and class
Java String
Java String Class
Java Immutable String
Java Immutable Class
String Buffer
String Builder
String Buffer vs String
String Builder vs String Buffer
String Tokenizer in Java
Java Array
Java Exceptions Handling
Java Try-Catch block
Java Multiply Catch Block
Java Finally Block
Java Throws Keyword
Java Throw Keyword
Java Exception Propagation
Java Throw vs Throws
Final vs Finally vs Finalize
Exception Handling With Method Overridding
Java Multithreading
Lifecycle and States of a Thread in Java
How to create a thread in Java
Thread Scheduler in Java
Sleeping a thread in Java
Calling run() method
Joining a thread in Java
Naming a thread in Java
Thread Priority
Daemon Thread
Thread Pool
Thread Group
Shutdown hook
Multitasking vs Multithreading
Garbage Collection
RunTime Class
Java Synchronization
Synchronized block in Java
Static Synchronization in Java
Deadlock in Java
Inter Thread Communication in Java
Interrupting Thread in Java
Reentrant Monitor in Java
Java Applet
Animation in Applet
EventHandling in Applet
Display image in Applet
Displaying Graphics in Applet
Parameter in Applet
Java 8 Features
Java Lambda Expressions
Method References
Functional Interfaces
Java 8 Stream
Base64 Encode Decode
Default Method
for Each() Method
Collectors class
String Joiner Class
Optional Class
JavaScript Nashron
Parallel Array Sort
Type Interface
Parameter Reflection
Type and Repeating Annotations
JDBC Improvements

Data types in Java

When we create variable it is nothing but reserved memory locations to store values. This means when you create variable you reserve memory space,now the operating system allocates memory and determines what can be put in the reserved memory based on a variable's data type. You may thus store integers, decimals, or characters in variables by giving them alternative data types.

Table Of Content

  • Data types in Java
  • Type of DataType
  • Unicode System
  • Why java uses Unicode System






In Java, there are two categories of data types:


  • Premetive Data Type Data types that are considered primitive include booleans, chars, bytes, short ints, long ints, floats, and doubles.
  • Non Premetive Data Type Non-primitive data Classes, Interfaces, and Arrays are examples of non-primitive data types.

In java all variables must be declared before its use. Because java is a statically-typed programming language that is why we need to declare variable's type and name
Types of Data Type

In Java we have 8 different type of premitive data type

  • boolean data type
  • byte data type
  • char data type
  • short data type
  • int data type
  • long data type
  • float data type
  • double data type





S.N Data Type Default Value Default size
1. boolean false 1 bit
2. byte 0 1 byte
3. char '\u0000' 2 byte
4. short 0 2 byte
5. int 0 4 byte
6. long 0L 8 byte
7. float 0.0f 4 byte
8. double 0.0d 8 byte

Byte
  • byte data type is a basic data type in java
  • It is an integer with two's complement and an 8-bit sign.
  • Its value range between -128 to 127 (inclusive).
  • byte data type minimum and maximum values are -128 and 127.
  • When memory optimization are most needed, such in huge arrays, the byte data type is used because a byte is four times smaller than an integer, thus space is saved .
  • The "int" data type can likewise be replaced with this byte data type.
Example:
byte  a = 10,  byte  b = -20;  
Boolean Data Type
  • Only the true and false values are stored using the Boolean data type. This data type is utilised for straightforward true/false flags.
  • The Boolean data type represents a single piece of data, however its exact "size" cannot be determined.
Example:
Boolean  a = false 



Short Data Type
  • Short data type is 16-bit signed two's complement integer.
  • Its range of values ranges from -32,768 to 32,767.
  • The default value is zero (0).
Example:
short s = 10000,  short   r = -5000   
Int Data Type
  • Int data type is a 32-bit signed two's complement integer.
  • Its value ranges between - 2,147,483,648 (-2^31) to 2,147,483,647 (2^31 -1), respectively (inclusive).
  • 2,147,483,648 is its smallest value and 2,147,483,647 is its highest value.
  • The default value is 0.
  • Unless there is no memory issue, the int data type is often chosen as the default data type for integral values.
Example:
int  s = 100,  int   r = 500   
Long Data Type
  • Lond data type is a two's complement, 64-bit long data type.
  • Between -9,223,372,036,854,775,808(-2^63) and 9,223,372,036,854,775,807(2^63 -1) are its possible values (inclusive).
  • Its minimum and maximum value is -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 respectively.
  • The default value is 0.
  • When you want a wider range of values than int, the long data type is used
Example:
long s = 10000L,  long   r = -200000L     



Float Data Type
  • A single-precision 32-bit IEEE 754 floating point is the float data type.
  • It has an infinite value range.
  • If you need to save memory in sizable arrays of floating point integers, it is advised to use a float (instead of a double).
  • Never use the float data type for accurate numbers like cash.
  • The default value is 0.0F.
Example:
Integer s = 195.5f    
Double Data Type
  • A double-precision 64-bit IEEE 754 floating point is the double data type.
  • It has an infinite value range.
  • Like float, the double data type is frequently used for decimal numbers.
  • Additionally, it's never a good idea to utilise the double data type for exact numbers like money.
  • The default value is 0.0d.
Example:
double s = 12.3 
Char Data Type
  • char data type is 16-bit Unicode character.
  • Its value range is from '\u0000'(0) to '\uffff' (65,535)
  • We can store character using char data type.
Example:
character letter = "A"  



Unicode System

The majority of the world's written languages can be represented using the universal international standard character encoding known as Unicode.


Unicode System in Java


A code that converts characters into numbers must exist in order for a computer system to store text and numbers that humans can understand.


A character encoding standard called Unicode is used to define the appropriate code. The process of allocating a number to each character is known as character encoding. The primary goal of Unicode is to standardise various language encoding systems in order to reduce confusion among computer systems that use restrictive encoding standards like ASCII.


Why java uses Unicode System?

The Unicode standards were developed at a period when Java was evolving and had a much smaller character set. When the Unicode Transformed Format (UTF)-16 was created, Java was meant to use it. Java's "char" data type was initially utilised to represent 16-bit Unicode. Java therefore uses the Unicode standard.


  • Before Unicode there where many language standers like ASCII (American Standard Code for Information Interchange) for the United States.
  • ISO 8859-1 for Western European Language.
  • KOI-8 for Russian.
  • GB18030 and BIG-5 for Chinese



Two issues resulted from this:


  • In many linguistic standards, certain letters are assigned to a specific code value.
  • Variable length encodings are used for languages with vast character sets.
  • Some frequently used characters may be encoded in a single byte, while others need two or more.
  • A new language standard called the Unicode System was created to address these issues.
  • Since each character in unicode takes up two bytes, Java also uses two bytes for each character.
  • lowest value: u0000
    highest value: uFFFF
Java Operators Next »
« Perv Next »


Post your comment





Read Next Topic
Java Tutorial - Topic
What is Java
History of Java
Freature of Java
Difference Between Java & C++
Java Environment Set Up
Java Hello World Program & its Internal Process
JDK, JRE and JVM
Java Variables
Java Data Types & Unicode System
Java Operators
Java Keywords
Java Naming Convention
Read Other Java Chapter
Java Topic
Java Basic Tutorial
Java Control Statements
Java Classes & Object
Java Inheritance
Java Polymorphism
Java Abstraction
Java Encapsulation
Java OOPs Miscellaneous
Java Array
Java String
Java Exception Handling
Java Multithreading
Java Synchronization
Java Applet
Java 8 Features
Java 9 Features
Java Collection
Java Mcq
Java Interview Question
Tools
  

Useful Links

  • Home
  • Blog
  • About us
  • Contact Us
  • Privacy policy

Contact Us

Police Colony
Patna, Bihar
India

Email:

About DockerTpoint


India's largest site for Programming Tutorial as well as BANK, SSC, RAILWAY exam
and Campus placement preparation.